

#include <event.h>
#include <stdint.h>
#include <pthread.h>
#include <time.h>
//#include <goahead.h>
#include <uuid/uuid.h>
#define		INIT			1
#define		SND_ACK_CHLG	2
#define		SND_RDS_AUTH	3
#define		RTN_PORTAL_AUTH	4
#define		CONNECTED		5

// portal proto
#define PRT_PROTO_HW	0
#define PRT_PROTO_NS	1
//  Limit
#define	AUTH_LIMIT		256
#define NAME_SIZE		128
#define PASSWD_SIZE		32

typedef struct rad_sess {
	uint8_t auth[16];
	char sessid[128];	//  用户Radius认证ID
	uint8_t	id;
} rad_sess_t;

typedef struct prt_sess {
	char username[NAME_SIZE];	//用户名
	uint8_t	challenge[16];
	uint8_t	chappwd[16];
	char passpwd[NAME_SIZE];						//passwd
	uint8_t wtpid[16];
	uint8_t usermac[6];	//用户的MAC地址
	uint8_t version;	//协议版本号
	uint32_t userip;	//portal用户的IP地址
	uint32_t nasip;
	uint32_t sn;
	uint16_t serialNo;	//报文的序列号
	uint16_t reqid;
	uint8_t	method;
//	Webs *wp;
	char *fristpage;
//	char *jsonpcallback;
	struct evhttp_request *req;
	struct evbuffer *repBuf;
	struct sockaddr_in prtaddr;//portal服务器的地址 用于通信
} prt_sess_t;

enum {
	AUTH_SESS_IDLE = 0,
	AUTH_SESS_BUSY = 1
};

typedef struct auth_timer {
	uint8_t type;		//  定时器类型
	uint8_t	init;		//  定时器初始化标志
	uint8_t enable;		//  定时器打开标志
	uint8_t count;		//  超时次数
	uint32_t ident;
	struct event timer;		//  定时器
} auth_timer_t;

typedef struct acct_sess {
//	uint8_t id;				// 	标识符
	uint32_t inspeed;		// 	下载带宽
	uint32_t outspeed;		//  上传带宽
	uint32_t sesstime;		// 	剩余时长
	uint32_t gflow;			//  流量配额 ，单位GB
	uint32_t bflow;			//  流量配额 ，	单位Bytes
} acct_sess_t;

typedef struct auth_sess {
	uint32_t flag;
	uint32_t sessid;
	uint32_t state;
	prt_sess_t *portal;
	rad_sess_t *radius;
	acct_sess_t *acct;
	auth_timer_t timer;
} auth_sess_t;


//extern pthread_rwlock_t G_auth_sess_lock;
//
//#define auth_sess_wrlock()  pthread_rwlock_wrlock(&G_auth_sess_lock);
//
//#define  auth_sess_rdlock()  pthread_rwlock_rdlock(&G_auth_sess_lock);
//
//#define  auth_sess_unlock()   pthread_rwlock_unlock(&G_auth_sess_lock);
//
//#define auth_sess_wrlock()  do{int sss=0;}while(0);
////
//#define  auth_sess_rdlock()  do{int sss=0;}while(0);
////
//#define  auth_sess_unlock()   do{int sss=0;}while(0);



 